function exp_SLICE()
    test_runtime();
    %test_probabilty();
    %test_Wages();
    %test_NBA();
end

function test_Wages()
    savfilename='test_wages.txt';
    load('wages.mat','Age','Education','Experience','Wage');
    data=[Wage,Age, Experience];
%     [corrplanes,sups]=SLICE(data,1,0.0006,0.3,100);
%     corratts={}; 
%     for i=1:length(corrplanes)
%         corratts{i}=[1,2,3];
%     end
%     displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
    
    [corrplanes,sups]=CARE(data, 3, 0.001,  0.5);
    corratts={}; 
    for i=1:length(corrplanes)
        corratts{i}=[1,2,3];
    end
    displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
end

function test_NBA()
    savfilename='test_nba.txt';
    load('nba2.mat','gp','minutes','reb','ast','stl');
    data=[minutes,ast,reb];
%     [corrplanes,sups]=SLICE(data,1,0.0006,0.5,100);
%     corratts={}; 
%     for i=1:length(corrplanes)
%         corratts{i}=[1,2,3];
%     end
%     displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);   
    [corrplanes,sups]=CARE(data, 3, 0.0006,  0.5);
    corratts={}; 
    for i=1:length(corrplanes)
        corratts{i}=[1,2,3];
    end
    displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
end

function [runtimes]=test_runtime()
    runtimes_datasize=[];
    for i=1:10
        data=DXF4C4(50+i*100);
        time=0;
        tic;
        [corrplanes,sups]=SLICE(data,1,0.001,0.20,100);
        time=toc;
        runtimes_datasize=[runtimes_datasize,time];
    end
    runtimes_featuresize=[];
    for i=1:10
        data=D300FXC4(1+2*i);
        time=0;
        tic;
        [corrplanes,sups]=SLICE(data,1,0.001,0.20,100);
        time=toc;
        runtimes_featuresize=[runtimes_featuresize,time];
    end
    runtimes_datasize
    runtimes_featuresize
end


function [prob, numrets]=test_probabilty()
    success=0;
    maxtime=100;
    probs=[];
    savfilename='test_LOSTCO.txt';
    for i=1:maxtime
        data=D300F3C3();
        [corrplanes,sups]=SLICE(data,1,0.0006,0.3,100);
        if length(corrplanes)>=3
            success=success+1;
        end
        corratts={};
        for i=1:length(corrplanes)
            corratts{i}=[1,2,3];
        end
        displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
    end    
    prob=success/maxtime;
    probs=[probs, prob];
    probs
    success=0;
    for i=1:maxtime
       data=D400F3C4();
        [corrplanes,sups]=SLICE(data,1,0.0006,0.20,100);
        if length(corrplanes)>=4
            success=success+1;
        end
        corratts={};
        for i=1:length(corrplanes)
            corratts{i}=[1,2,3];
        end
        displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
    end 
    prob=success/maxtime;
    probs=[probs, prob];
    success=0;
    probs
    for i=1:maxtime
        data=D600F4C4();
        [corrplanes,sups]=SLICE(data,1,0.001,0.20,100);
        if length(corrplanes)>=4
            success=success+1;
        end
        corratts={};
        for i=1:length(corrplanes)
            corratts{i}=[1,2,3,4];
        end
        displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
    end
    prob=success/maxtime;
    probs=[probs, prob];
    success=0;
    probs
    for i=1:maxtime
        data=D600F4C4();
        [corrplanes,sups]=SLICE(data,1,0.001,0.20,100);
        if length(corrplanes)>=4
            success=success+1;
        end
        corratts={};
        for i=1:length(corrplanes)
            corratts{i}=[1,2,3,4];
        end
        displaycorrelations(corrplanes,sups,corratts,0.01,savfilename);
    end
    prob=success/maxtime;
    probs=[probs, prob];
    success=0;
    probs
    for i=1:maxtime
        data=D500F4C5();
        [corrplanes,sups]=SLICE(data,1,0.001,0.18,100);
        if length(corrplanes)>=5
            success=success+1;
        end
        corratts={};
        for i=1:length(corrplanes)
            corratts{i}=[1,2,3,4];
        end
        displaycorrelations(corrplanes,sups,corratts,0.01, savfilename);
    end
    prob=success/maxtime;
    probs=[probs, prob];
    success=0;
    probs
    fp=fopen(savfilename,'wt');
    for i=1:length(probs)
        fprintf(fp,'%d\n',probs(i));
    end
    fclose(fp);
end

function data=D300F3C3()
    numpoints = 100;
    x1=randint(1,numpoints,[-200,200]);
    y1=randint(1,numpoints,[-200,200]);
    z1=2*x1+y1+randn(1,numpoints); % 2x1+x2-x3=0
    %z1=randint(1,numpoints,[-200,200]);
    x2=randint(1,numpoints,[-200,200]);
    y2=randint(1,numpoints,[-200,200]);
    z2=x2*3-y2*5+randn(1,numpoints); % 3x1-5x2-x3=0
    %z2=randint(1,numpoints,[-200,200]);
    x3=randint(1,numpoints,[-200,200]);
    y3=randint(1,numpoints,[-200,200]);
    z3=-4*x3-2*y3+100+randn(1,numpoints); % 4x1+2x2+x3=100
    x=[x1,x2,x3];
    y=[y1,y2,y3];
    z=[z1,z2,z3];
    data=[ x',y',z'];
end

function data=D400F3C4()
    numpoints = 100;
    r=800;
    x1=randint(1,numpoints,[-r,r]);
    y1=randint(1,numpoints,[-r,r]);
    z1=2*x1+y1+randn(1,numpoints); % 2x1+x2-x3=0
    x2=randint(1,numpoints,[-r,r]);
    y2=randint(1,numpoints,[-r,r]);
    z2=x2*3-y2*5+randn(1,numpoints); % 3x1-5x2-x3=0
    x3=randint(1,numpoints,[-r,r]);
    y3=randint(1,numpoints,[-r,r]);
    z3=-4*x3-2*y3+100+randn(1,numpoints); % 4x1+2x2+x3=100
    x4=randint(1,numpoints,[-r,r]);
    y4=randint(1,numpoints,[-r,r]);
    z4=-0.3*x4+0.5*y4+10+randn(1,numpoints); 
    x=[x1,x2,x3,x4];
    y=[y1,y2,y3,y4];
    z=[z1,z2,z3,z4];
    data=[ x',y',z'];
end

function data=D600F4C4()
    numpoints = 150;
    r=800;
    x1=randint(1,numpoints,[-r,r]);
    y1=randint(1,numpoints,[-r,r]);
    r1=randint(1,numpoints,[-r,r]);
    z1=2*x1+y1-0.5*r1+randn(1,numpoints); % 2x1+x2-x3=0
    x2=randint(1,numpoints,[-r,r]);
    y2=randint(1,numpoints,[-r,r]);
    r2=randint(1,numpoints,[-r,r]);
    z2=x2*3-y2*5+2*r2+randn(1,numpoints); % 3x1-5x2-x3=0
    x3=randint(1,numpoints,[-r,r]);
    y3=randint(1,numpoints,[-r,r]);
    r3=randint(1,numpoints,[-r,r]);
    z3=-4*x3-2*y3+r3+100+randn(1,numpoints); % 4x1+2x2+x3=100
    x4=randint(1,numpoints,[-r,r]);
    y4=randint(1,numpoints,[-r,r]);
    r4=randint(1,numpoints,[-r,r]);
    z4=-0.3*x4+0.5*y4-3*r4+10+randn(1,numpoints); 
    x=[x1,x2,x3,x4];
    y=[y1,y2,y3,y4];
    r=[r1,r2,r3,r4];
    z=[z1,z2,z3,z4];
    data=[ x',y',r',z'];
end

function data=D500F4C5()
    numpoints = 100;
    r=800;
    x1=randint(1,numpoints,[-r,r]);
    y1=randint(1,numpoints,[-r,r]);
    r1=randint(1,numpoints,[-r,r]);
    z1=2*x1+y1-0.5*r1+randn(1,numpoints); % 2x1+x2-x3=0
    x2=randint(1,numpoints,[-r,r]);
    y2=randint(1,numpoints,[-r,r]);
    r2=randint(1,numpoints,[-r,r]);
    z2=x2*3-y2*5+2*r2+randn(1,numpoints); % 3x1-5x2-x3=0
    x3=randint(1,numpoints,[-r,r]);
    y3=randint(1,numpoints,[-r,r]);
    r3=randint(1,numpoints,[-r,r]);
    z3=-4*x3-2*y3+r3+100+randn(1,numpoints); % 4x1+2x2+x3=100
    x4=randint(1,numpoints,[-r,r]);
    y4=randint(1,numpoints,[-r,r]);
    r4=randint(1,numpoints,[-r,r]);
    z4=-0.3*x4+0.5*y4-3*r4+10+randn(1,numpoints); 
    x5=randint(1,numpoints,[-r,r]);
    y5=randint(1,numpoints,[-r,r]);
    r5=randint(1,numpoints,[-r,r]);
    z5=-3*x5+0.5*y5+6*r5-100+randn(1,numpoints); 
    x=[x1,x2,x3,x4,x5];
    y=[y1,y2,y3,y4,y5];
    r=[r1,r2,r3,r4,r5];
    z=[z1,z2,z3,z4,z5];
    data=[ x',y',r',z'];
end

function data=DXF4C4(numpoints)
    r=800;
    x1=randint(1,numpoints,[-r,r]);
    y1=randint(1,numpoints,[-r,r]);
    r1=randint(1,numpoints,[-r,r]);
    z1=2*x1+y1-0.5*r1+randn(1,numpoints); % 2x1+x2-x3=0
    x2=randint(1,numpoints,[-r,r]);
    y2=randint(1,numpoints,[-r,r]);
    r2=randint(1,numpoints,[-r,r]);
    z2=x2*3-y2*5+2*r2+randn(1,numpoints); % 3x1-5x2-x3=0
    x3=randint(1,numpoints,[-r,r]);
    y3=randint(1,numpoints,[-r,r]);
    r3=randint(1,numpoints,[-r,r]);
    z3=-4*x3-2*y3+r3+100+randn(1,numpoints); % 4x1+2x2+x3=100
    x4=randint(1,numpoints,[-r,r]);
    y4=randint(1,numpoints,[-r,r]);
    r4=randint(1,numpoints,[-r,r]);
    z4=-0.3*x4+0.5*y4-3*r4+10+randn(1,numpoints); 
    x=[x1,x2,x3,x4];
    y=[y1,y2,y3,y4];
    r=[r1,r2,r3,r4];
    z=[z1,z2,z3,z4];
    data=[ x',y',r',z'];
end

function data=D300FXC4(numfeatures)
    numpoints=100;
    r=800;
    xyz1=randint(numfeatures-1,numpoints,[-r,r]);
    z1=zeros(1,numpoints);
    for i=1:numfeatures-1
        z1=z1+i*xyz1(i);
    end
    xyz2=randint(numfeatures-1,numpoints,[-r,r]);
    z2=zeros(1,numpoints);    
    for i=1:numfeatures-1
        z2=z2+((-1)^(i-1))*xyz2(i);
    end
    xyz3=randint(numfeatures-1,numpoints,[-r,r]);
    z3=zeros(1,numpoints);
    for i=1:numfeatures-1
        z3=z3+(i*((-1)^(i-1)))*xyz2(i);
    end
    xyz4=randint(numfeatures-1,numpoints,[-r,r]);
    z4=zeros(1,numpoints);
    for i=1:numfeatures-1
        z4=z4+(i^2/3)*xyz2(i);
    end
    
    xyz=[xyz1,xyz2,xyz3,xyz3];
    z=[z1,z2,z3,z4];
    data=[xyz',z'];
end

